home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / head / head.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  1KB  |  74 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6.  
  7. /*
  8.  *  HEAD.C
  9.  *
  10.  *  print first 10 lines of a file
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <lib/version.h>
  17.  
  18. #ifdef _DCC
  19. IDENT("head",".3");
  20. DCOPYRIGHT;
  21. #endif
  22.  
  23. void head(FILE *);
  24.  
  25. int
  26. main(ac, av)
  27. int   ac;
  28. char **av;
  29. {
  30.     int   i;
  31.  
  32. #ifndef unix
  33.     expand_args(ac, av, &ac, &av);
  34. #endif
  35.  
  36.     for (i = 1; i < ac; ++i) {
  37.     FILE *fi;
  38.  
  39.     if (fi = fopen(av[i], "r")) {
  40.         if (ac > 2)
  41.         {
  42.         fputs("--- ", stdout);
  43.         fputs(av[i],  stdout);
  44.         puts(" ---");
  45. //        printf("--- %s ---\n", av[i]);
  46.         }
  47.         head(fi);
  48.         fclose(fi);
  49.         puts("");
  50.     } else {
  51.         fputs("--- ", stdout);
  52.         fputs(av[i],  stdout);
  53.         puts(" --- (unable to open)");
  54. //        printf ("--- %s --- (unable to open)\n", av[i]);
  55.     }
  56.     }
  57.     return(0);
  58. }
  59.  
  60. void
  61. head(fi)
  62. FILE *fi;
  63. {
  64.     char buf[256];
  65.     short i;
  66.  
  67.     for (i = 0; i < 10; ++i) {
  68.     if (fgets(buf, sizeof(buf), fi) == NULL)
  69.         break;
  70.     fputs(buf, stdout);
  71.     }
  72. }
  73.  
  74.